package cn.itsource.dd.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.basic.util.PageInfo;
import cn.itsource.dd.domain.Detail;
import cn.itsource.dd.mapper.DetailMapper;
import cn.itsource.dd.query.TypeQuery;
import cn.itsource.dd.service.IDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DetailServiceImpl extends BaseServiceImpl<Detail>implements IDetailService {
    @Autowired
    private DetailMapper detailMapper;

    @Override
    @Transactional
    public void save(Detail detail){
        if(detail.getId()==null){
            //添加
            detailMapper.save(detail);
        }
        //修改
        detailMapper.update(detail);
    }

    @Override
    public PageInfo<Detail> findAllById(TypeQuery typeQuery) {
            //查询总条数
           Long total=detailMapper.findTotals(typeQuery);
            //判断总条数是否为0
            if(total.equals(0L)){
                return new PageInfo<>();
            }
            //查询列表
            List<Detail> list=detailMapper.findAllById(typeQuery);
        return new PageInfo<>(list,total);
    }
}
